﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYAuto.MonitorData.Chitunion.Bll.MonitorNotice.Interface;
using XYAuto.MonitorData.Chitunion.Infrastruct.Verification;

namespace XYAuto.MonitorData.Chitunion.Bll.MonitorNotice
{
    public abstract class AbstractNotices : VerifyOperateBase
    {
        protected SendDto SendDto;
        protected AbstractNotices(SendDto sendDto)
        {
            SendDto = sendDto;
        }

        public abstract ReturnValue Send();

        /// <summary>
        /// successUser 多条
        /// </summary>
        /// <param name="successUser"></param>
        protected virtual void DoAddNoticeLog(List<string> successUser)
        {
            //todo:addlog
            //这里的耦合度高，应该用依赖注入
            if (!successUser.Any())
            {
                return;
            }
            var logList = successUser.Select(s => new Entities.MonitorPushNoticeLog
            {
                MonitorId = SendDto.MonitorId,
                NoticeKey = SendDto.NoticeKey,
                NoticeToUser = s
            }).ToList();

            Dal.MonitorPushNoticeLog.Instance.Insert(logList);

        }

        protected virtual ReturnValue VerifySendDto()
        {
            var retValue = new ReturnValue();
            if (SendDto == null)
                return CreateFailMessage(retValue, "2001", "VerifySendDto sendDto is null");
            return retValue;
        }
    }
}
